/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package YottaTron.Actions;

import YottaTron.Sprites.Sprite;
import YottaTron.Actions.Action;
import YottaTron.Runner;
import YottaTron.Sprites.PlayerSprite;
import org.lwjgl.util.Timer;

/**
 *
 * @author Cenda
 */
public class TurnAction extends Action {
    float totalTime = 0;
    int smer;

    public TurnAction(Sprite s, int smer, float startingTime, Runner r) {
        sprite = s;
        this.smer = smer;
        this.r = r;
        this.startingTime = startingTime;
        if (smer == 1) {
            type = Action.TURN_RIGHT_ACTION;
        } else {
            type = TURN_LEFT_ACTION;
        }

        iterations = 0;

        PlayerSprite player = ((PlayerSprite) s);
        if (player.controllable) {
            player.addLastAction(this);
        }
    
    saveToHistory = true;
    }

    public boolean nextStep(float deltaTime){
        if (finished) {
            
            
            sprite.changeDirection(sprite.getDirection()+sprite.getTurnSpeed()*smer*deltaTime);
            sprite.variableChanged = true;
             totalTime += deltaTime;
//             System.out.println("total Time = " + totalTime);
//            System.out.println("expected Total Time = " + (finishTime - startingTime));
            return false;
        }

       if(iterations==0){
          
//           float deltaTime = currentTime - startingTime;
//           System.out.println("zatacim po dobu " + deltaTime);
//            totalTime += deltaTime;
//       //System.out.println(r.deltaTime - r.getDeltaTimeFrom(startingTime));
//       sprite.changeDirection(sprite.getDirection()+sprite.getTurnSpeed()*smer*deltaTime);
       }else{
            
             totalTime += deltaTime;
       sprite.changeDirection(sprite.getDirection()+sprite.getTurnSpeed()*smer*deltaTime);
       sprite.variableChanged = true;
        }
        // System.out.println("zatacim" + iterations + " uhel je " + sprite.getRealDirection()/Math.PI*180);
        iterations++;
        return true;



    }

    
}
